import requests

import time

from lxml import etree
for i in range(100):
    time.sleep(1)
    res = requests.get(f'https://office.fang.com/zu/house/i3{i}/')
    print(f"正在爬取 第 {i} 页")
# print(res.text)
    tree = etree.HTML(res.text)
    items = tree.xpath('//dl[@class="clearfix"]')
    # print(items)
    for item in items:
        # print(item)
        href = item.xpath('.//h4[@class="clearfix"]/a/@href')
        title = item.xpath('.//span[@class="tit_shop"]/text()')
        area = item.xpath('.//p[@class=" add_shop"]/span/text()')
        bsm = item.xpath('.//p[@class="tel_shop"]/text()[contains(., "㎡")]')
        fool = item.xpath('.//p[@class="tel_shop"]/text()[contains(., "层")]')
        price = item.xpath('.//span[@class="red"]//text()')
        href1 = 'https://office.fang.com/' + href[0]
        print(href1,title,area,bsm, fool, price)

        # res2 = requests.get(href1)
        # print(res2.text)